/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 *
 * $Id$
 */
package org.sgt.datamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreEMap;
import org.eclipse.emf.ecore.util.InternalEList;
import org.sgt.datamodel.DataStore;
import org.sgt.datamodel.DatamodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Data Store</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.sgt.datamodel.impl.DataStoreImpl#getEObjects <em>EObjects</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.DataStoreImpl#getKnownEObjects <em>Known EObjects</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DataStoreImpl extends ENamedElementImpl implements DataStore {
	/**
	 * The cached value of the '{@link #getEObjects() <em>EObjects</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEObjects()
	 * @generated
	 * @ordered
	 */
	protected EList<EObject> eObjects;

	/**
	 * The cached value of the '{@link #getKnownEObjects() <em>Known EObjects</em>}' map.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKnownEObjects()
	 * @generated
	 * @ordered
	 */
	protected EMap<String, EList<EObject>> knownEObjects;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DataStoreImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DatamodelPackage.Literals.DATA_STORE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EObject> getEObjects() {
		if (eObjects == null) {
			eObjects = new EObjectContainmentEList<EObject>(EObject.class, this, DatamodelPackage.DATA_STORE__EOBJECTS);
		}
		return eObjects;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EMap<String, EList<EObject>> getKnownEObjects() {
		if (knownEObjects == null) {
			knownEObjects = new EcoreEMap<String,EList<EObject>>(DatamodelPackage.Literals.EOBJECT_MAP, EObjectMapImpl.class, this, DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS);
		}
		return knownEObjects;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DatamodelPackage.DATA_STORE__EOBJECTS:
				return ((InternalEList<?>)getEObjects()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS:
				return ((InternalEList<?>)getKnownEObjects()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DatamodelPackage.DATA_STORE__EOBJECTS:
				return getEObjects();
			case DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS:
				if (coreType) return getKnownEObjects();
				else return getKnownEObjects().map();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DatamodelPackage.DATA_STORE__EOBJECTS:
				getEObjects().clear();
				getEObjects().addAll((Collection<? extends EObject>)newValue);
				return;
			case DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS:
				((EStructuralFeature.Setting)getKnownEObjects()).set(newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DatamodelPackage.DATA_STORE__EOBJECTS:
				getEObjects().clear();
				return;
			case DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS:
				getKnownEObjects().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DatamodelPackage.DATA_STORE__EOBJECTS:
				return eObjects != null && !eObjects.isEmpty();
			case DatamodelPackage.DATA_STORE__KNOWN_EOBJECTS:
				return knownEObjects != null && !knownEObjects.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //DataStoreImpl
